package com.chenyaowei.web.controller.marketing.coupon;

import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.core.page.TableDataInfo;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.marketing.domain.CywCouponSpuCategoryRelation;
import com.chenyaowei.marketing.service.ICywCouponSpuCategoryRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 优惠券分类关联Controller
 *
 * @author 陈耀威
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/marketing/couponSpuCategoryRelation")
public class CywCouponSpuCategoryRelationController extends BaseController
{
    @Autowired
    private ICywCouponSpuCategoryRelationService cywCouponSpuCategoryRelationService;

    @GetMapping("/list/{couponId}")
    public AjaxResult selectListByCouponId(@PathVariable("couponId") Long couponId)
    {
        List<CywCouponSpuCategoryRelation> list = cywCouponSpuCategoryRelationService.selectListByCouponId(couponId);
        return success(list);
    }

    /**
     * 查询优惠券分类关联列表
     */
//    @PreAuthorize("@ss.hasPermi('marketing:couponSpuCategoryRelation:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywCouponSpuCategoryRelation cywCouponSpuCategoryRelation)
    {
        startPage();
        List<CywCouponSpuCategoryRelation> list = cywCouponSpuCategoryRelationService.selectCywCouponSpuCategoryRelationList(cywCouponSpuCategoryRelation);
        return getDataTable(list);
    }

    /**
     * 导出优惠券分类关联列表
     */
    @PreAuthorize("@ss.hasPermi('marketing:couponSpuCategoryRelation:export')")
    @Log(title = "优惠券分类关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywCouponSpuCategoryRelation cywCouponSpuCategoryRelation)
    {
        List<CywCouponSpuCategoryRelation> list = cywCouponSpuCategoryRelationService.selectCywCouponSpuCategoryRelationList(cywCouponSpuCategoryRelation);
        ExcelUtil<CywCouponSpuCategoryRelation> util = new ExcelUtil<CywCouponSpuCategoryRelation>(CywCouponSpuCategoryRelation.class);
        util.exportExcel(response, list, "优惠券分类关联数据");
    }

    /**
     * 获取优惠券分类关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('marketing:couponSpuCategoryRelation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywCouponSpuCategoryRelationService.selectCywCouponSpuCategoryRelationById(id));
    }

    /**
     * 新增优惠券分类关联
     */
//    @PreAuthorize("@ss.hasPermi('marketing:couponSpuCategoryRelation:add')")
    @Log(title = "优惠券分类关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywCouponSpuCategoryRelation cywCouponSpuCategoryRelation)
    {
        return toAjax(cywCouponSpuCategoryRelationService.insertCywCouponSpuCategoryRelation(cywCouponSpuCategoryRelation));
    }

    /**
     * 修改优惠券分类关联
     */
    @PreAuthorize("@ss.hasPermi('marketing:couponSpuCategoryRelation:edit')")
    @Log(title = "优惠券分类关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywCouponSpuCategoryRelation cywCouponSpuCategoryRelation)
    {
        return toAjax(cywCouponSpuCategoryRelationService.updateCywCouponSpuCategoryRelation(cywCouponSpuCategoryRelation));
    }

    /**
     * 删除优惠券分类关联
     */
    @PreAuthorize("@ss.hasPermi('marketing:couponSpuCategoryRelation:remove')")
    @Log(title = "优惠券分类关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywCouponSpuCategoryRelationService.deleteCywCouponSpuCategoryRelationByIds(ids));
    }
}
